/*
 * @Author: wzh
 * @Date: 2021-11-30 23:04:34
 * @LastEditTime: 2021-12-01 02:38:59
 * @LastEditors: wzh
 * @Description: 
 * @FilePath: \LoRa32OLED\src\app_PCStatus.cpp
 * 可以输入预定的版权声明、个性签名、空行等
 */

#include "WiFi.h"
#include "stdio.h"
#include "Arduino.h"

#include "WString.h"
#include "app_PCSttus.h"
#include "oled.h"







char tcpu[25], scpuuti[25], scpuclk[25], vcpu[25];//用来存着4个数值
char id[15];
char value[25];
byte inByte;



void app_PCStatus()
{
    if (Serial.available() > 0)
    {   //数据帧格式：?TCPU=37!
        inByte = Serial.read();
        if (inByte == '?')
        {
            int i = 0;
            while (inByte != '=')
            {
                while (Serial.available() == 0)
                    ;
                inByte = Serial.read();
                if (inByte != '=')
                {
                    id[i++] = inByte;
                }
                else
                {
                    id[i] = '\0';
                }
            }
            i = 0;
            while (inByte != '!')
            {
                while (Serial.available() == 0)
                    ;
                inByte = Serial.read();
                if (inByte != '!')
                {
                    value[i++] = inByte;
                }
                else
                {
                    value[i] = '\0';
                }
            }
            i = 0;
            Serial.println(id); //如果需要显示其他的信息，去上位机输出里查名称
            Serial.println(value);
            if (strcmp("TCPUPKG", id) == 0)
                strcpy(tcpu, value);
            if (strcmp("SCPUUTI", id) == 0)
                strcpy(scpuuti, value);
            if (strcmp("SCPUCLK", id) == 0)
                strcpy(scpuclk, value);
            if (strcmp("VCPU", id) == 0)
                strcpy(vcpu, value);
            PCStatus_refresh();
        }
    }

}


void PCStatus_refresh()
{
    char msg[20];
    sprintf(msg,"GPU Temp: %s'C",tcpu);
    OLED_Debug(msg,0);

    sprintf(msg,"CPU Util: %s%%",scpuuti);
    OLED_Debug(msg,1);

    sprintf(msg,"CPU Freq: %sGhz",scpuclk);
    OLED_Debug(msg,2);

    sprintf(msg,"CPU Volt: %sV",vcpu);
    OLED_Debug(msg,3);
}






